package com.icemelon.catdog.service;

import com.icemelon.catdog.dao.MessageMapper;
import com.icemelon.catdog.pojo.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class UserMessageServiceImpl implements UserMessageService {

    @Autowired
    private MessageMapper messageMapper;

    @Override
    public void sendMessage(Integer senderId, Integer receiverId, String message) {
        Message msg= new Message();
        msg.setReceiver(receiverId);
        msg.setSender(senderId);
        msg.setContent(message);
        messageMapper.insert(msg);

    }

    @Override
    public Message getMessageById(Integer id) {
        return messageMapper.selectById(id);
    }

    @Override
    public void deleteMessageByUserId(Integer[] ids) {
        List<Integer> listIds = Arrays.asList(ids);
        messageMapper.deleteBatchIds(listIds);
    }

}
